var directBuyNeedLogin = true;
sessionUserInfo  = null;

// 切换验证码方法
function changeValidateImage(){
	$("img[name='validateImage']").attr("src",webRootPath +"/hnwt-biz/image/captcha/image.jsp?"+(new Date()).getTime());
	//document.getElementsByName("validateImage").src=webRootPath + "/rand.action?t="+new Date().getTime();
}
function getSessionInfo() {
	$.ajax({
        type: "POST",//用POST方式传输
        dataType:"json",//数据格式:JSON 
        url:webRootPath+"/getSessionInfo.action",//目标地址 
        async:false,//作用是防止在ajax成功调用之前就调用这个时候数据个数还没有初始化
        error: function(data) {
			window.location = webRootPath+"/self_service/logon.action";
		},
        success:function(json) {
			sessionUserInfo = json ;
        }
    });
	return sessionUserInfo;
}
	
var redirecetURL = null;	//url 登录之后转跳的地址
var jsFunctionName = "";
var actionCode = null;		//弹出层显示的关闭弹出层的文子，1不登陆直接订购，2取消，其他也是取消

var callFn = function(){
	isPupupOpen = false;
	if(redirecetURL != null && redirecetURL != '') {
		window.location = webRootPath+redirecetURL;
	}
};

function validateSession(url,operationCode) {	//url 登录之后转跳的地址，operationCode 弹出层显示的关闭弹出层的文子，1不登陆直接订购，2取消，其他也是取消
	redirecetURL = url;
	jsFunctionName = url;	
	actionCode = operationCode;
	if(!directBuyNeedLogin) {
		return true;
	}
	var isSessionOn = true;
	$.ajax({
        type: "POST",//用POST方式传输
        dataType:"text",//数据格式:JSON 
        url:webRootPath+"/hnbiz/uamlogin/uam-login!isSessionOn.action",//目标地址 
        async:false,//作用是防止在ajax成功调用之前就调用这个时候数据个数还没有初始化
        success:function(text) {			
        	if(text != "true") {        		
        		popupDiv();
        		isSessionOn = false;
        	}
        }
    });
    return isSessionOn;
}

function popupDiv() {
	isPupupOpen = true;
	$.ajax({
        type: "POST",//用POST方式传输
        dataType:"text",//数据格式:JSON 
        url:webRootPath+"/hnbiz/uamlogin/uam-login!userLoginPage.action?modelPage="+actionCode+"&jsFunctionName="+jsFunctionName,//目标地址 
        async:false,//作用是防止在ajax成功调用之前就调用这个时候数据个数还没有初始化
        error: function(data) {
			showAlertAwake(new Date(),400,"系统提示","系统正忙,请稍后再试！",1);	
		},
        success:function(text) {  		
        	easyDialog.open({
			  container : {
			    header:"用户登录",
			    content : text
			  }		 
			});
        }
    });   
}


/**
 *弹出层登陆方式
 */
 var submitFormIdPupup = "cellphoneloginformPupup";
function submitPopupLoginForm(formid) {			
	//submitFormIdPupup = formid;
	//if($("p.validateCodePupup").get(0).style.display != "") {		
		var codeValue = $("#"+submitFormIdPupup+ " input[name='validateCode']").val();
		var unumber = $("#"+submitFormIdPupup+ " input[name='productId']").val();
		var upwd = $("#"+submitFormIdPupup+ " input[name='userPwd']").val();
		var logintype = $("#"+submitFormIdPupup+ " input[name='userType']").val();
		if(unumber =="" ||upwd == ""){
			$("#"+submitFormIdPupup+ " p.logonMessagePPupup").show();
			$("#"+submitFormIdPupup+ " span.loginMessagePupup").addClass("err");
			$("#"+submitFormIdPupup+ " span.loginMessagePupup").html("获取信息失败,请验证输入信息！");
			return;
		}
		if(logintype!=="2000006"){
			if(upwd == "111111" || upwd == "123456" || upwd == "111333" )
			{
				   showAlertAwake(new Date(),600,"系统提示","您的密码设置过于简单，为了防止被他人盗用，请通过下面的方式更改您的客户密码：\n•  方式一：个人及家庭客户，请您持本人有效证件到中国电信营业厅获取本人的客户密码；\n•  方式二：个人及家庭客户，请您使用本人的固定电话、小灵通或电信手机本机拨打电信客服热线10001--按1键--按3键--按1键获取客户密码。 ",1);
				   return;
			}
		}
		codeValue = $.trim(codeValue);
		if(codeValue == "") {
			$("#"+submitFormIdPupup+ " p.logonMessagePPupup").show();
			$("#"+submitFormIdPupup+ " span.loginMessagePupup").addClass("err");
			$("#"+submitFormIdPupup+ " span.loginMessagePupup").html("请输入验证码");
			return;
		}
	//}	
	$("#"+submitFormIdPupup+ " p.logonMessagePPupup").show();
	$("#"+submitFormIdPupup+ " span.loginMessagePupup").removeClass("loginmsg err");
	$("#"+submitFormIdPupup+ " span.loginMessagePupup").html("登录中，请稍后……");
	var myform = document.getElementById(submitFormIdPupup);
	window.document.getElementById(submitFormIdPupup+"submitLoginBtn").style.visibility = "hidden";
	
	var postData = $("#"+submitFormIdPupup).serialize();	
	//postData = postData + "&userType="+$("#userType").val();
	$.ajax({
        type: "POST",
        dataType:"json",
        url:webRootPath+"/hnbiz/uamlogin/uam-login!validataLogin.action",
        async:true,
        data:postData,
        error: function() {
			
			$("#"+submitFormIdPupup+ " p.logonMessagePPupup").show();
			$("#"+submitFormIdPupup+ " span.loginMessagePupup").addClass("loginmsg err");
			$("#"+submitFormIdPupup+ " span.loginMessagePupup").html("系统忙,请稍后再试");
			window.document.getElementById(submitFormIdPupup+"submitLoginBtn").style.visibility = "";
			
			// 登录失败，更新验证码
			changeValidateImage();
		},
        success:function(data) {			
        	if(data.result == 'success') {        		
        		var ds = data.ds;
        		var paramUam = data.paramUam;
        		document.getElementById("wtmsg").value = paramUam;         	
    			document.loginformPupup.submit.click();   			
        	} else if(data.result == 'reg') {        		
        		easyDialog.close();	
				easyDialog.open({
				  container : {
				    content : '恭喜您登录成功...'
				  },
				  autoClose : 2000
				});	
				window.location = webRootPath+"/service/manage"
        	}else {        		
        		$("#"+submitFormIdPupup+ " p.logonMessagePPupup").show();
				$("#"+submitFormIdPupup+ " span.loginMessagePupup").addClass("loginmsg err");
				$("#"+submitFormIdPupup+ " span.loginMessagePupup").html(data.errorMsg);
				window.document.getElementById(submitFormIdPupup+"submitLoginBtn").style.visibility = "";
				
				// 登录失败，更新验证码
				changeValidateImage();
        	}
        }
    });
    //window.document.getElementById("submitLoginBtn").style.visibility = "hidden";
}

function adslOneClickLogin(formid) {
	submitFormIdPupup = formid;
	$("#"+submitFormIdPupup+ " p.logonMessagePPupup").show();
	$("#"+submitFormIdPupup+ " span.loginMessagePupup").removeClass("loginmsg err");
	$("#"+submitFormIdPupup+ " span.loginMessagePupup").html("登录中，请稍候……");
	if (formid != "1") {
		var myform = document.getElementById(formid);
		window.document.getElementById(formid+"submitLoginBtn").style.visibility = "hidden";
	}	
	$.ajax({
        type: "POST",
        dataType:"json",
        url:webRootPath+"/hnbiz/uamlogin/uam-login!adslLogin.action",
        async:true,
        data:"",
        error: function() {
			if (formid != "1") {				
				$("#" + submitFormIdPupup + " p.logonMessagePPupup").show();
				$("#" + submitFormIdPupup + " span.loginMessagePupup").addClass("loginmsg err");
				$("#" + submitFormIdPupup + " span.loginMessagePupup").html("系统忙,请稍后再试");
				window.document.getElementById(submitFormIdPupup + "submitLoginBtn").style.visibility = "";				
			}else{
				showAlertAwake(new Date(), 400, "系统提示", "系统正忙,请稍后再试！", 1);
			}
		},
        success:function(data) {
        	if(data.result == 'success') {
        	/*	easyDialog.close();	
				easyDialog.open({
				  container : {
				    content : '登陆中，请稍候...'
				  },
				  autoClose : 2000
				});	*/
				window.parent.parent.location.href = data.url
        	} else {
        		if (formid != "1") {
	        		$("#"+submitFormIdPupup+ " p.logonMessagePPupup").show();
					$("#"+submitFormIdPupup+ " span.loginMessagePupup").addClass("loginmsg err");
					$("#"+submitFormIdPupup+ " span.loginMessagePupup").html(data.errorMsg);
					window.document.getElementById(submitFormIdPupup+"submitLoginBtn").style.visibility = "";
				}else{
					showAlertAwake(new Date(), 400, "系统提示", data.errorMsg, 1);
				}
        	}
        }
    });
}

function loginFail(errorMessage) {
	
	$("#"+submitFormIdPupup+ " p.logonMessagePPupup").show();
	$("#"+submitFormIdPupup+ " span.loginMessagePupup").addClass("loginmsg err");
	$("#"+submitFormIdPupup+ " span.loginMessagePupup").html(errorMessage);
	$("p.validateCodePupup").show();
	window.document.getElementById(submitFormIdPupup+"submitLoginBtn").style.visibility = "";
	
	// 登录失败，更新验证码
	changeValidateImage();
}

function changeLoginType(selectObj) {
	
	$("#productIdLabel").html(selectObj.options[selectObj.selectedIndex].text+"：");
	$("#userType").val(selectObj.value);
}

function  changeLoginPattern(obj) {
	
	if($(obj).val() == 1) {
		$("#reUserType").attr("disabled","");
		selectObj = document.getElementById("reUserType");
		$("#productIdLabel").html(selectObj.options[selectObj.selectedIndex].text+"：");
		$("#userType").val(selectObj.value);
	} else {
		$("#reUserType").attr("disabled","disabled");
		$("#userType").val("2000005");
		$("#productIdLabel").html("注册账号：");
	}
}

function jsCallBack(functionName) {
	var realfunction = functionName+"()";
	eval(realfunction); 
}



//弹出层登陆调用方法
function submitLoginForm() {
	$("#loginMessage").html("登录中，请稍后……");
	var postData = $("#userLoginForm").serialize();
	postData = postData + "&userType="+$("#userType").val();
	$.ajax({
        type: "POST",
        dataType:"text",
        url:webRootPath+"/self_service/validateLogin.action",
        async:true,
        data:postData,
        error: function() {
			showAlertAwake(new Date(),400,"系统提示","系统正忙，请稍后再试！",1);
		},
        success:function(data) {
        	if(data == 'success') {
        		easyDialog.close();
        		easyDialog.open({
				  container : {
				    content : '恭喜您登录成功...'
				  },
				  autoClose : 2000,
				  callback : callFn
				});
				
        	} else {
        		$("#loginMessage").html(data);
        		window.document.getElementById("submitLoginBtn").style.visibility = "visible";
        	}
        }
    });
    window.document.getElementById("submitLoginBtn").style.visibility = "hidden";
}

function submitPageLoginForm() {
	$("#loginMessage").html("登录中，请稍后……");
	var myform = document.getElementById("pageLoginForm");
	window.document.getElementById("submitLoginBtn").style.visibility = "hidden";
	myform.submit();
}

function submitPupupLoginForm(formid) {
    $("#logonMessageP").show();
	$("#loginMessage").html("登录中，请稍后……");
	var myform = document.getElementById(formid);
	window.document.getElementById(formid+"submitLoginBtn").style.visibility = "hidden";
	myform.submit();
}

function closePopupDiv(){
	easyDialog.close();
	directBuyNeedLogin = false;
}

function cancelPopupDiv(){
	easyDialog.close();
}
var isPupupOpen = false;

function openLogin(actionCode) {
	var url = webRootPath+"/jsp/login/login.jsp?actionCode="+actionCode;
	var browserWidth = document.body.clientWidth;
	var browserHeight = document.body.clientHeight;
	var left = (browserWidth-370)/2;
	var top = (browserHeight-210)/2;
  	window.open (url, "登录", "height=210, left="+left+",top="+top+",width=370, toolbar =no, menubar=no,scrollbars=no, resizable=no, location=no, status=no");
}

function validateSesionDialog(url,operationCode) {
	redirecetURL = url;
	actionCode = operationCode;
	if(!directBuyNeedLogin) {
		return true;
	}
	var isSessionOn = true;
	$.ajax({
        type: "POST",//用POST方式传输
        dataType:"text",//数据格式:JSON 
        url:webRootPath+"/isSessionOn.action",//目标地址 
        async:false,//作用是防止在ajax成功调用之前就调用这个时候数据个数还没有初始化
        success:function(text) {
        	if(text == "false") {
        		var t = openLogin(operationCode);
        		isSessionOn = false;
        	}
        }
    });
    return isSessionOn;
}

function logintype(obj,classid,shownumber,formid){
	submitFormIdPupup = formid;
	$(obj).siblings('a').removeClass('on');$(obj).addClass('on');
	$('#logintPupup').removeClass().addClass(classid);
	$('.loginformPupup').hide();$('.'+shownumber).show();
	
	// 切换登录类型时，更新验证码
	changeValidateImage();
}

function showGetDymamicHrefPupup(obj){
	if($(obj).val() == "04") {
		$("#getDynamicHrefPupup").show();
		$("#findPwdPupup").hide();
		$("#cellphonePwdTypeLabelPupup").html("随机密码：");
	} else {
		$("#getDynamicHrefPupup").hide();
		$("#findPwdPupup").show();
		$("#cellphonePwdTypeLabelPupup").html("手机密码：");
	}
}

var flagPupup = true;
var sysSecondPupup = 20;
var interValObjPupup = null;

function getDynamicPWDPupup() {
	var phoneNum = $("#cellphonePupup").val();
	if(phoneNum.length != 11) {
		$("#logonMessagePPupup").show();
		$("#loginMessagePupup").html("请输入手机号");
		return;
	}
	if(flagPupup) {
		$("#loginMessagePupup").html("请稍等一会...");
		flagPupup = false;
	} else {
		$("#loginMessagePupup").html("请稍等一会再操作");
		return;
	}
	interValObjPupup = window.setInterval(setRemainTimePupup, 1000);
	$.ajax({
        type: "POST",//用POST方式传输
        dataType:"test",//数据格式:JSON 
        url:webRootPath+"/hnselfservice/uamlogin/uam-login!sendSMS.action",//目标地址 
        data:"accountID="+$("#cellphonePupup").val(),
        async:false,//作用是防止在ajax成功调用之前就调用这个时候数据个数还没有初始化
        success:function(data) {			
				$("#getDynamicHrefPupup").html("");
				$("#logonMessagePPupup").show();
				$("#loginMessagePupup").removeClass("err");
				$("#loginMessagePupup").addClass("loginmsg");
				$("#loginMessagePupup").html(data);		
        }
    });
}

function setRemainTimePupup() {  
  		if (sysSecondPupup > 0) {  
    	sysSecondPupup = sysSecondPupup - 1;  
    	var second = Math.floor(sysSecondPupup % 20);             // 计算秒      
   		$("#showTimeMsgPupup").html(second);  
	} else {//剩余时间小于或等于0的时候，就停止间隔函数  
  			window.clearInterval(interValObjPupup);  
  			//这里可以添加倒计时时间为0后需要执行的事件  
  			flagPupup = true;
  			sysSecondPupup = 20;
  			$("#getDynamicHrefPupup").html("再次获取");
  			$("#showTimeMsgPupup").html("");  
 		}  
}

var canCommit = true;
/*  
$(document).keyup(function(event){ 
	if(canCommit &&　event.which== 13) {
		canCommit = false;
		submitPopupLoginForm();
		return;
	}
});
*/

//保留两位小数
function changeTwoDecimal_f(x){
	var f_x = parseFloat(x);
	if (isNaN(f_x))
	{
		alert('function:changeTwoDecimal->parameter error');
		return false;
	}
	var f_x = Math.round(x*100)/100;
	var s_x = f_x.toString();
	var pos_decimal = s_x.indexOf('.');
	if (pos_decimal < 0)
	{
		pos_decimal = s_x.length;
		s_x += '.';
	}
	while (s_x.length <= pos_decimal + 2)
	{
		s_x += '0';
	}
	return s_x;
  }
  function loadPage(queryUrl,divclass){
	var url=CMSPath+queryUrl;
	$.ajax({
		url:url,
		success:function(text){			
				$(""+divclass+"").html(text);
		},
		error:function(r,t,e){
			showAlertAwake(new Date(),400,"系统提示",url,1);
		}
		});
} 
//公用时段获取方法
function timeinterval(){
	var timeBanner = "凌晨";
	var today = new Date();
	var hour = today.getHours();
	if (hour >= 5 && hour < 8) {
		timeBanner = "上午";
	}
	if (hour >= 8 && hour < 12) {
		timeBanner = "上午";
	}
	if (hour >= 12 && hour < 14) {
		timeBanner = "中午";
	}
	if (hour >= 14 && hour < 17) {
		timeBanner = "下午";
	}
	if (hour >= 17 && hour < 19) {
		timeBanner = "傍晚";
	}
	if (hour >= 19 && hour < 23) {
		timeBanner = "晚上";
	}
	return timeBanner;
}
function getheadUserinfo(userName,areaName){
	var timeBanner = timeinterval();
	var innertext ="";	
	if (userName != null && userName != "") {
		innertext = "<SPAN id=li_name>" + userName + "</SPAN> " + timeBanner + "好，欢迎来到中国电信！[<A href='"+webRootPath+"/hnbiz/uamlogin/uam-login!logout.action'>退出</A>]";		
		$("#cityArea").hide();
	}else{
		innertext = ""+timeBanner+"好，欢迎来到中国电信！请[<a href='javascript:loginHref();'>登录</a>] ";
	}
	$("#top_dis_city").html(areaName);
	$("#WelcomeMsg").empty().html(innertext);
}
//[<a href='"+webRootPath+"/hnselfservice/register/new-user-register!showpage.action'>注册</a>]

//显示地域
function showArea(superRegionId){	
	var hdRegion=$("#hdregion").val();	
    $("#selRegion").html("");
    if (superRegionId == "0") {
        AddOption("--请选择--", "", "selRegion");
    }
    else {
    	 var postData = "superRegionId=" + superRegionId;
    	 $.ajax({
    	        type: "POST",//用POST方式传输
    	        dataType:"Xml",//数据格式:JSON 
    	        url:webRootPath+"/region/region!getChildRegionById.do",//目标地址 
    	        async:true,//作用是防止在ajax成功调用之前就调用这个时候数据个数还没有初始化
    	        data:postData,    	        
    	        error: function() {    		 		
    				showAlertAwake(new Date(),400,"系统提示","系统正忙,请稍候再试！",1);	
    			},
    	        success:function(data) {
    				 $(data).find('ObjArray').each(function(){    					
    				        var id = $(this).find("region__id").text();
    				        var name = $(this).find("region__name").text();     				       		
    		                AddOption(name, id, "selRegion");     				       
    				  });    				
    	        }
    	    }); 
    }   
}
//切换城市
function chooseCity(rid, rname) {
	$.ajax({type: "post",   
        url: webRootPath+"/hnbiz/homepage/home-page!chooseCity.action",
        dataType: "html",   
        data: "rid=" + rid,  
        async: false, 
        success: function(result){  
        	var res = String($.trim(result));          	
            	if(res == "success"){
            		$("#top_dis_city").html(rname);
					parent.location.reload();//刷新当前页面
            	} 
        	} 
        }); 
}
//得到下拉框当前选的的文本（不是VALUE）
function getTxt(str){	
	 var checkText=$(str).find("option:selected").text(); 	 
	return checkText;	
}
//父窗口跳转到密码修改页面
function parentherf(){
	javascript:window.parent.location=webRootPath+"/hnselfservice/password/password!index.action";
}
//跳转帮助支持公共页面
function helpherf(url){	
	javascript:window.location=webRootPath+"/hnselfservice/homepage/home-page!helpquery.action?"+url;
}
//打开新窗口
function newWindow(url){	
	window.open(url);
}
//生成一个iframe并且加载一个Url到指定的div
function iframeFunction (divName,uiframe,url){		
	  var html = "<iframe src='" + url + "'"
	  html += " width='100%' id ='"+uiframe+"' onload='autoHeight(this);' scrolling='no' frameborder='0' allowtransparency='true'>"
	  html += " </iframe>";
	  $("#"+divName).html(html);
}
//iframe动态调整自身高度
 var objiframe;
function autoHeight(myiframe){
 	objiframe= myiframe;	
	if(objiframe.addEventListener||objiframe.readyState=="complete"){
		setTimeout("iframeHeight()","200");//为了保证IFRAME内容被浏览器解析完毕增加延迟获取高度
	}
 }
 function iframeHeight(){
	if(objiframe.Document){//ie自有属性
		objiframe.style.height =objiframe.Document.body.scrollHeight+25+'px';
		//alert("I高度是："+objiframe.Document.body.scrollHeight);
	}else if(objiframe.contentDocument){//ie,firefox,chrome,opera,safari
		objiframe.height = objiframe.contentDocument.body.offsetHeight+25+'px';
		//alert("Y高度是："+objiframe.contentDocument.body.offsetHeight);			
	}
} 
 //加载CMS区块公用方法(参数地址)
function loadPage(queryUrl,divclass){
	var url=CMSPath+queryUrl;
	$.ajax({
		url:url,
		success:function(text){			
				$(""+divclass+"").html(text);
		},
		error:function(r,t,e){
		//	showAlertAwake(new Date(),400,"系统提示",url,1);
		}
		});
}
 //加载CMS区块公用方法(HTML地址)
function loadForHtml(htmlUrl,divclass){
	var url=CMSbase+htmlUrl;
	$.ajax({
		url:url,
		success:function(text){
			$(""+divclass+"").html(text);
		},
		error:function(r,t,e){
		//	showAlertAwake(new Date(),400,"系统提示",url,1);
		}
	});
}

function getCmsFullUrl(url){
	var requrl="";
	var i = url.indexOf("?")+1;
	var n = url.indexOf("=",1);
	if (i > 0) {
		var vname = url.substring(i, n);		
		if (vname == "url") {
			requrl = CMSbase + url.substring(n+1, url.length);			
		}
		else if (vname == "id") {
			requrl = CMSPath + url.substring(n, url.length);
		}else{
			requrl = CMSPath + url.substring(i, url.length);
		}		
	}
	return requrl;
}
//返回上一个页面（保留上一个页面数据）支持火狐
function gohistory(){
	history.go(-1);
	return false;
}


 
//回车事件处理			
function strdown(evt){
    //获得键盘按下事件,支持ie，ff，google，safari，opera
	var keyCode = (typeof evt.keyCode != 'undefined') ? evt.keyCode : evt.which;
	if (keyCode == 13) {
		var str = $("#searchKeyWord").val();
		if (str != "您可以搜索产品/活动/问题等"&&str!="") {
			if (!checkWord()) {
				showAlertAwake(new Date(), 400, "系统提示", "只允许输入中文字符、字母、数字、-、(、)和空格组成的字符串!", 1);
				return false;
			}
			else {
				$("#searchKeyWordId").val($("#searchKeyWord").val());
				$("#searchForm").submit();
			}
		}else{
			showAlertAwake(new Date(), 400, "系统提示", "请输入搜索关键字 !", 1);
			return false;
		}
	}
}
function sbsearch(){
   var str = $("#searchKeyWord").val();
	if (str != "您可以搜索产品/活动/问题等"&&str!="") {
		//var url = "<c:url value='/eshop/search/search_search.do'/>";               
		if (!checkWord()) {
			showAlertAwake(new Date(), 400, "系统提示", "只允许输入中文字符、字母、数字、-、(、)和空格组成的字符串!", 1);
			return false;
		}
		 $("#searchForm").submit();
	}else{
		showAlertAwake(new Date(), 400, "系统提示", "请输入搜索关键字 !", 1);
		return false;
	}
}
function checkWord(){
    var str = $("#searchKeyWord").val();
    str = str.replace(/\s+/g, "");//去除所有空格
    var reg = /^[0-9A-Za-z\-()（）\u4E00-\u9FA5]+$/; //只允许输入中文字符、字母、数字、-、(、)和空格组成的字符串
    return reg.test(str);
}

//搜索框聚焦事件
function searchFocus(){
    var str = $("#searchKeyWord").val();
    str = str.replace(/\s+/g, "");//去除所有空格
    if (str == "您可以搜索产品/活动/问题等") {
        $("#searchKeyWord").val("");
        $("#searchKeyWord").addClass("focus");
    }
}

//搜索框失去焦点事件
function searchBlur(){
    var str = $("#searchKeyWord").val();
    str = str.replace(/\s+/g, "");//去除所有空格
    if (str == "") {
        $("#searchKeyWord").removeClass("focus");
        $("#searchKeyWord").val("您可以搜索产品/活动/问题等");
    }
}

//检查旺铺是否登陆
function checkWpLogin(type,path){
	$.ajax({
		url: path+"!checkLogin.action?type="+type,
		dataType:"json",
		type: 'POST',
		success:function(data) { 
			if(typeof(data.make)!='undefined'&&data.make=="success"){
				//已经登录了
				//如果是添加 type=add
				if(type=="add"){
					if(typeof(data.needAdd)!='undefined'&&data.needAdd == "no"){
						alert("该用户已经申请了旺铺！");
					}else{
						//跳转到添加页面
						window.parent.location.href = path+"!addInit.action"
					}
				}else if(type=="cancel"){
					//如果是取消订购
					if(typeof(data.noWinport)!='undefined'&&data.noWinport == "yes"){
						alert("该用户还没有申请旺铺！");
					}else{
						//跳转到添加页面
						window.parent.location.href = path+"!cancelInit.action"
					}
				}
			}else{
				//没有登录，或者登录的类型不对
				//var divUrl = path+"!getLoginDiv.action";
				//getWpLoginDiv(divUrl);
				if(typeof(data.errMsg)!='undefined'){
					alert(data.errMsg);
				}
				if(type=="cancel"){
					window.parent.location.href = path+"!getLoginDiv.action?rUrl="+path+"!cancelInit.action";
				}else{
					window.parent.location.href = path+"!getLoginDiv.action?rUrl="+path+"!addInit.action";
				}
			}
        },error:function(r,t,e){
			//showAlertAwake(new Date(),400,"系统提示","系统正忙，请稍后再试！",1);
			alert("系统正忙，请稍后再试！");
		}
	});
}

